/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.kota105.ui.generic;

import org.kota105.ui.generic.properties.Property;
import java.util.ArrayList;

/**
 *
 * @author pikpun
 */
public abstract class AbstractWidget extends View {

    public Layout parent;
    public boolean isRoot;

    public AbstractWidget() {
        defaultProperties = new ArrayList<Property>();
    }

    public void setParent(Layout layout) {
        this.parent = layout;
    }

    public Layout getParent() {
        return parent;
    }

    public void addProperty(Property property) {
        properties.add(property);
    }

    public void removeProperty(Property property) {
        properties.remove(property);
    }

    public void updateProperty(Property property) {
        if (defaultProperties.isEmpty()) {
            defaultProperties = getDefaultProperties();
        }
        if (property.getAttributeName().indexOf(Property.GENERIC_ANDROID_XML) == 0) {
            property.setAttributeName(property.getAttributeName().substring(Property.GENERIC_ANDROID_XML.length()));
        }
        for (int i = 0; i < defaultProperties.size(); i++) {
            if (property.getAttributeName().equals(defaultProperties.get(i).getAttributeName())) {
                System.out.println("set property for object : " + property.getAttributeName());
                defaultProperties.set(i, property);
                break;
            }
        }
    }

}
